package top.jiangqiang.qianyi.business.service.impl;

import org.springframework.stereotype.Service;
import top.jiangqiang.qianyi.business.model.request.UserInfoListRequest;
import top.jiangqiang.qianyi.business.model.request.UserInfoPageRequest;
import top.jiangqiang.qianyi.business.model.request.UserInfoSaveRequest;
import top.jiangqiang.qianyi.business.model.request.UserInfoUpdateRequest;
import top.jiangqiang.qianyi.business.model.response.UserInfoDetailResponse;
import top.jiangqiang.qianyi.business.model.response.UserInfoListResponse;
import top.jiangqiang.qianyi.business.model.response.UserInfoPageResponse;
import top.jiangqiang.qianyi.business.service.UserInfoService;
import top.jiangqiang.qianyi.common.base.model.response.PageResult;
import top.jiangqiang.qianyi.common.base.model.response.Result;
import top.jiangqiang.qianyi.common.base.service.impl.BaseServiceImpl;
import top.jiangqiang.qianyi.data.model.entity.UserInfo;
import top.jiangqiang.qianyi.data.service.UserInfoDbService;

import java.util.List;

/**
 * <p>
 * 用户信息 服务实现类
 * </p>
 *
 * @author JiangQiang
 * @since 2024-06-03
 */
@Service
public class UserInfoServiceImpl extends BaseServiceImpl<UserInfoDbService, UserInfo> implements UserInfoService {

    @Override
    public Result<PageResult<UserInfoPageResponse>> page(UserInfoPageRequest request) {
        PageResult<UserInfoPageResponse> page = request.toPage();
        return Result.ok(getBaseDbService().lambdaJoinWrapper().page(page, UserInfoPageResponse.class));
    }

    @Override
    public Result<List<UserInfoListResponse>> list(UserInfoListRequest request) {
        return Result.ok(getBaseDbService().lambdaJoinWrapper().list(UserInfoListResponse.class));
    }

    @Override
    public Result<Void> add(UserInfoSaveRequest request) {
        UserInfo userInfo = typeConverter.convert(request, UserInfo.class);
        save(userInfo);
        return Result.ok();
    }

    @Override
    public Result<Void> update(UserInfoUpdateRequest request) {
        UserInfo userInfo = typeConverter.convert(request, UserInfo.class);
        updateById(userInfo);
        return Result.ok();
    }

    @Override
    public Result<UserInfoDetailResponse> detail(Long id) {
        return Result.ok(getById(id, UserInfoDetailResponse.class));
    }

    @Override
    public Result<Void> delete(Long id) {
        removeById(id);
        return Result.ok();
    }

}